package com.ciwong.epaper.widget.catalog.base;

import java.util.ArrayList;
import java.util.List;

public abstract class BaseNode<T, E> {

    private List<BaseNode> childrenList = new ArrayList<>();//所有的孩子节点
    private T selfId;//自身id
    private T parentId;//父节点id(当为第一级时，parentId为-1)
    private int selfLevel=-1;//自身所处的层级(默认都为复议-1)
    private boolean isLastLevel;//是否是叶子结点（最底层）
    private boolean isFirstLevel;//是否是第一级根节点结点
    private boolean isParentNode;//是否是有子节点的结点（是否是个父节点）
    private E nodeContent;//节点内容（可以是对象）
    private BaseNode parentNode;//是否是叶子结点（最底层）
    private boolean isExpand;//是否展开
    private boolean isChecked;//是否选中



    public abstract boolean isChildOf(BaseNode desNode);//自己是否是目标节点的子节点

    public abstract boolean isParentOf(BaseNode desNode);//自己是否是目标节点的父节点


    public List<BaseNode> getChildrenList() {
        return childrenList;
    }

    public void setChildrenList(List<BaseNode> childrenList) {
        this.childrenList = childrenList;
    }

    public T getSelfId() {
        return selfId;
    }

    public void setSelfId(T selfId) {
        this.selfId = selfId;
    }

    public T getParentId() {
        return parentId;
    }

    public void setParentId(T parentId) {
        this.parentId = parentId;
    }

    public int getSelfLevel() {
        if (selfLevel < 0){//如果是 负数 的话就递归获取
            //因为是树形结构，所以此处想要得到当前节点的层级
            //，必须递归调用，但是递归效率低下，如果每次都递归获取会严重影响性能，所以我们把第一次
            //得到的结果保存起来避免每次递归获取
            int level = parentNode == null ? 1 : parentNode.getSelfLevel()+1;
            selfLevel = level;
            return selfLevel;
        }
        return selfLevel;
    }

    public void setSelfLevel(int selfLevel) {
        this.selfLevel = selfLevel;
    }

    public boolean isLastLevel() {
        return childrenList.size()==0;
    }

    public boolean isFirstLevel() {
        return parentNode==null;
    }
    public boolean isParentNode() {
        return childrenList.size()>0;
    }

    public E getNodeContent() {
        return nodeContent;
    }

    public void setNodeContent(E nodeContent) {
        this.nodeContent = nodeContent;
    }

    public BaseNode getParentNode() {
        return parentNode;
    }

    public void setParentNode(BaseNode parentNode) {
        this.parentNode = parentNode;
    }
    public boolean isExpand() {
        return isExpand;
    }

    public void setExpand(boolean expand) {
        isExpand = expand;
    }
    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

}
